import Scanner from "./Scanner.js"
import nestedTokens from './nestedTokens'
// 将截取的字符串转换为tokens

export default function parseTemplateTokens(templateStr) {
    let tokens = []
    // 实例一个扫描器
    var scanner = new Scanner(templateStr)
    var words
    while (!scanner.eos()) {
        words = scanner.scanUtil('{{')
        scanner.scan('{{')
        if (!words == '') {
            tokens.push(['text', words])
        }
        words = scanner.scanUtil('}}')
        scanner.scan('}}')
        if (!words == '') {
            // 遇到#，提取#作为第一个元素，第二个去掉#号
            if (words[0] == '#') {
                tokens.push(['#', words.substring(1)])
            } else if (words[0] == '/') {
                tokens.push(['/', words.substring(1)])
            }else{
                tokens.push(['name', words])
            }
        }
    }
    return nestedTokens(tokens)
}